package com.seven.good.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;

@Configuration
public class SwaggerConfig{

    @Bean
    public Docket docket1(Environment environment){
        // 在dev环境获取的flag才为真
        Profiles profiles = Profiles.of("dev");
        boolean flag = environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
                            .enable(flag)//是否启动swagger
                            .groupName("ytj")
                            .apiInfo(apiInfo())
                            .select()
                            .apis(RequestHandlerSelectors.basePackage("com.seven.good.controller"))
                            .build();
    }
    @Bean
    public Docket docket2(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("lqj")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.seven.good.controller"))
                .build();
    }

    public ApiInfo apiInfo(){
        Contact contact = new Contact("ytj","","");//作者联系信息
        return new ApiInfo(
                "ytj的API文档",
                "商品前台模块",
                "V1.0",
                "",
                contact,
                "",
                "",
                new ArrayList<>()
        );
    }
}
